package com.easy.dfc.web;

import com.easy.common.bean.Result;
import com.easy.common.constant.EnumConfig;
import com.easy.core.web.BaseController;
import com.easy.dfc.entity.ParaAllProduct;
import com.easy.dfc.entity.ParaEnrollQuery;
import com.easy.dfc.entity.UserPara;
import com.easy.dfc.service.DealerHomeService;
import com.easy.dfc.service.DealerListService;
import com.easy.dfc.service.UsersetService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping(value = "${apiPath}/DealerList")
public class DealerListController extends BaseController {

    @Resource
    private DealerListService dealerListService;

    @Resource
    private UsersetService usersetService;

    /**
     * 品牌馆/潮流馆-本周最大牌
     * @param user userId,token
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "BestOnWeek", method = RequestMethod.POST)
    public Result BestOnWeek(@RequestBody UserPara user, Model model) {
        try {
            if (!usersetService.VerifyToken(user.getUserId(), user.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return dealerListService.BestOnWeek(user.getType());
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 品牌馆/潮流馆-Banner
     * @param user userId,token
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "Banner", method = RequestMethod.POST)
    public Result Banner(@RequestBody UserPara user, Model model) {
        try {
            if (!usersetService.VerifyToken(user.getUserId(), user.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.Banner(user.getType());
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }
    /**
     * 品牌馆/潮流馆-今日我大牌
     * @param user userId,token
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "BestToday", method = RequestMethod.POST)
    public Result BestToday(@RequestBody UserPara user, Model model) {
        try {
            if (!usersetService.VerifyToken(user.getUserId(), user.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.BestToday(user.getPageIndex(),user.getPageSize(),user.getType());
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }
    /**
     * 品牌馆/潮流馆-今日我大牌更多。
     * @param user userId,token
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "BestTodayMore", method = RequestMethod.POST)
    public Result BestTodayMore(@RequestBody UserPara user, Model model) {
        try {
            if (!usersetService.VerifyToken(user.getUserId(), user.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.BestTodayMore(user.getPageIndex(),user.getPageSize(),user.getType());
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }


    /**
     * 品牌馆/潮流馆-今日我最爆
     * @param user userId,token
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "BestProductToday", method = RequestMethod.POST)
    public Result BestProductToday(@RequestBody UserPara user, Model model) {
        try {
            if (!usersetService.VerifyToken(user.getUserId(), user.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.BestProductToday(user.getPageIndex(), user.getPageSize(), user.getType());
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }



    /**
     * 童品汇首页-商家列表
     * @param user userId,token
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "TPFactoryList", method = RequestMethod.POST)
    public Result TPFactoryList(@RequestBody UserPara user, Model model) {
        try {
            if (!usersetService.VerifyToken(user.getUserId(), user.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.TPFactoryList(user.getPageIndex(),user.getPageSize());
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 童品汇首页-商品列表
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "TPBestProduct", method = RequestMethod.POST)
    public Result TPBestProduct(@RequestBody ParaAllProduct para, Model model) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.TPBestProduct(para.getAgeGroup(), para.getPageIndex(),para.getPageSize());
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 尾品汇首页-商家列表
     * @param user userId,token
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "WPFactoryList", method = RequestMethod.POST)
    public Result WPFactoryList(@RequestBody UserPara user, Model model) {
        try {
            if (!usersetService.VerifyToken(user.getUserId(), user.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.WPFactoryList(user.getPageIndex(),user.getPageSize());
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 尾品汇首页-商品列表
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "WPBestProduct", method = RequestMethod.POST)
    public Result WPBestProduct(@RequestBody ParaAllProduct para, Model model) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.WPBestProduct(para.getAgeGroup(), para.getPageIndex(),para.getPageSize());
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 尾品汇首页-今日抢购、明日预告
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "WPProduct", method = RequestMethod.POST)
    public Result WPProduct(@RequestBody ParaAllProduct para, Model model) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.WPProduct(para.getAgeGroup(), para.getPageIndex(),para.getPageSize(),para.getDay());
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }


    /**
     * 天天焕新
     * @param user userId,token
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DayDayProduct", method = RequestMethod.POST)
    public Result DayDayProduct(@RequestBody UserPara user, Model model) {
        try {
            if (!usersetService.VerifyToken(user.getUserId(), user.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.DayDayProduct(user.getPageIndex(),user.getPageSize());
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 好厂推荐
     * @param user userId,token
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "NiceFactory", method = RequestMethod.POST)
    public Result NiceFactory(@RequestBody UserPara user, Model model) {
        try {
            if (!usersetService.VerifyToken(user.getUserId(), user.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.NiceFactory(user.getPageIndex(),user.getPageSize());
        } catch (Exception e) {
            Result rt = new Result();
            System.out.println("Error:"+e.toString());
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }


    /**
     * 天天特价首页
     * @param para
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DaySpecialOffer", method = RequestMethod.POST)
    public Result DaySpecialOffer(@RequestBody ParaAllProduct para, Model model) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.DaySpecialOffer(para.getAgeGroup(),para.getPageSize());
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 天天特价更多
     * @param para
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DaySpecialOfferMore", method = RequestMethod.POST)
    public Result DaySpecialOfferMore(@RequestBody ParaAllProduct para, Model model) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.DaySpecialOfferMore(para);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 订货会首页
     * @param para
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "OrderMeeting", method = RequestMethod.POST)
    public Result OrderMeeting(@RequestBody ParaEnrollQuery para, Model model) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.OrderMeeting(para);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 订货会详情
     * @param para
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "OrderMeetingDetail", method = RequestMethod.POST)
    public Result OrderMeetingDetail(@RequestBody ParaEnrollQuery para, Model model) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.OrderMeetingDetail(para);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 订货会详情列表
     * @param para
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "OrderMeetingDetailProduct", method = RequestMethod.POST)
    public Result OrderMeetingDetailProduct(@RequestBody ParaEnrollQuery para, Model model) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.OrderMeetingDetailProduct(para);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 聚爆款首页
     * @param para
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "ImplosionList", method = RequestMethod.POST)
    public Result ImplosionList(@RequestBody ParaAllProduct para, Model model) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            return dealerListService.ImplosionList(para);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }
    /**
     * 跳尾货场次
     * @param para
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "JumpTailTime", method = RequestMethod.POST)
    public Result JumpTailTime(@RequestBody ParaAllProduct para, Model model) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return dealerListService.JumpTailTime(para);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }
    /**
     * 跳尾货场次列表
     * @param para
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "JumpTailList", method = RequestMethod.POST)
    public Result JumpTailList(@RequestBody ParaAllProduct para, Model model) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return dealerListService.JumpTailList(para);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }
}
